(in-package :stumpwm)

(defcommand emacs () ()
  "run emacs"
  (run-or-raise "exec xfce4-terminal -T emacs --execute emacsclient -nw" '(:title "emacs")))

(defcommand do-toggle-touchpad () ()
	    (stumpwm:run-shell-command "/home/ragnarg/stumpwm/helper/toggle-touchpad.sh"))

(stumpwm:define-key stumpwm:*root-map* (stumpwm:kbd "C-e") "emacs")
;;(stumpwm:define-key stumpwm:*root-map* (stumpwm:kbd "e") "exec xfce4-terminal -T emacs --execute emacsclient -nw ")
(stumpwm:define-key stumpwm:*root-map* (stumpwm:kbd "C-c") "exec xfce4-terminal -T temp_term")
(stumpwm:define-key stumpwm:*root-map* (stumpwm:kbd "c") "exec xfce4-terminal")

;; super key topmap stuff
(stumpwm:define-key stumpwm:*top-map*  (stumpwm:kbd "s-v") "do-paste")
(stumpwm:define-key stumpwm:*top-map*  (stumpwm:kbd "s-XF86Launch5") "do-screensaver")

(stumpwm:define-key stumpwm:*top-map*  (stumpwm:kbd "s-t") "exec xte \"str `date +%T`\"")
(stumpwm:define-key stumpwm:*top-map*  (stumpwm:kbd "s-d") "exec xte \"str `date +%F`\"")

;;(stumpwm:define-key stumpwm:*top-map*  (stumpwm:kbd "s-XF86Launch9") "load-menu")
(defcommand do-paste () ()
	    (stumpwm:run-shell-command "/usr/bin/xte 'mousedown 2' 'mouseup 2'"))


; define keys
(defmacro defkey-top (key cmd)
  `(define-key *top-map* (kbd ,key) ,cmd))

(defmacro defkeys-top (&rest keys)
  (let ((ks (mapcar #'(lambda (k) (cons 'defkey-top k)) keys)))
    `(progn ,@ks)))

(defkeys-top
;;  ("F12"          "switch-screen")
  ("XF86HomePage" "loadrc")
  ("XF86Calculator" "exec gnome-calculator")
;;  ("XF86Mail" 	    "run-email")
  ("Menu"          "loadrc")
  ("M-Print"        "")
;;  ("XF86Search" "toggle-gott-spe")
  ("XF86Sleep"      "display-current-window-info")

  ("XF86AudioLowerVolume" "exec amixer -q set Master 5- unmute")
  ("XF86AudioRaiseVolume" "exec amixer -q set Master 5+ unmute")
  ("XF86AudioMute"        "exec amixer -q set Master toggle")
  ("XF86AudioPrev"  "")
  ("XF86AudioPlay"  "")
  ("XF86AudioNext"  "")
  ("XF86TouchpadToggle" "do-toggle-touchpad"))



;;** 12 (info "(stumpwm)Hooks")

;; display the key sequence in progress
(defun key-press-hook (key key-seq cmd)
  (declare (ignore key))
  (unless (eq *top-map* *resize-map*)
    (let ((*message-window-gravity* :bottom-right))
      (message "Key sequence: ~a" (print-key-seq (reverse key-seq))))
    (when (stringp cmd)
      ;; give 'em time to read it
      (sleep 0.001))))

(defmacro replace-hook (hook fn)
  `(remove-hook ,hook ,fn)
  `(add-hook ,hook ,fn))

(remove-hook *key-press-hook* 'key-press-hook)


;;;;/sys/devices/pci0000:00/0000:00:02.0/backlight/acpi_video1
